<template>
	<view class="pageBox">
		<head-navbar>
			<view class="">历次更新说明</view>
		</head-navbar>
		<view class="section">
			<view class="versionCur">
				当前版本：{{getVersionCur}}
			</view>
			<u-time-line>
				<u-time-line-item nodeTop="2" v-for="(item,index) in list">
					<!-- 此处自定义了左边内容，用一个图标替代 -->
					<template v-slot:node>
						<view class="u-node" :style="{background:$store.state.color.primary}" v-if="item.Status=='启用'">
							<!-- 此处为uView的icon组件 -->
							<u-icon name="pushpin-fill" color="#fff" :size="24"></u-icon>
						</view>
					</template>
					<template v-slot:content>
						<view>
							<view class="u-order-title">版本号:{{item.Version}}</view>
							<view class="u-order-desc">
								<view class="row" v-for="(item2,index2) in item.updateList" :key="index2">
									<text class="type" :class="{add:item2.type=='新增',repair:item2.type=='修复',optimize:item2.type=='优化'}">{{item2.type}}</text>
									<view class="remarks">
										{{item2.remark}}
									</view>
								</view>
							</view>
							<view class="u-order-time">{{item.CreatedTime}}</view>
						</view>
					</template>
				</u-time-line-item>
			</u-time-line>
		</view>
	</view>
</template>

<script>
	import {getUpdateLog} from '../../api/global/index.js';
	export default {
		data() {
			return {
				list:[]
			}
		},
		computed:{
			getVersionCur(){
				return this.$store.state.appVersion.split('_')[2]
			}
		},
		onLoad() {
			this.getData();
		},
		methods: {
			/**
			 * 统一获取函数
			 */
			getData(){
				this.getUpdateLog();
			},
			/**
			 * 获取历次更新列表
			 */
			async getUpdateLog(){
				let {data:{Success,Message,Annex}}=await getUpdateLog();
				if(Success){
					Annex.forEach(v=>{
						v.updateList=[];
						v.Remarks.split(';').forEach((v2)=>{
							v.updateList.push({
								type:v2.replace(/^\n+|\n+$/g,"").split('|')[0],
								remark:v2.replace(/^\n+|\n+$/g,"").split('|')[1],
							})
						})
					})
					this.list=Annex;
				}else{
					this.utils.toast(Message)
				}
			},
			/**
			 * 查看更多
			 */
			showMore(data){
				this.$refs.showMore.open(data);
			}
		}
	}
</script>

<style lang="scss">
	@import "./index.scss";
</style>
